// <editor-fold defaultstate="collapsed" desc="GNU GPLv3 Header">
/*
 * File:   Daubechies.java
 *
 * Copyright (C) 2013 Robert Antoni Buj Gelonch <rbuj@uoc.edu>
 * Copyright (C) 2013 David Megias Jimenez <dmegias@uoc.edu>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
// </editor-fold>
package uoc.libwavelets.Daubechies;

import java.util.List;

/**
 *
 * @author Robert Antoni Buj Gelonch <rbuj@uoc.edu>
 * @version 1.0
 * @since 2013-08-15
 */
public class Daubechies {

    public int grade;
    public DecompositionLPF dLPF;
    public DecompositionHPF dHPF;
    public ReconstructionLPF rLPF;
    public ReconstructionHPF rHPF;

    /**
     *
     * @param grade
     *
     * @since 2013-08-15
     */
    public Daubechies(int _grade) {
        grade = _grade;
        dLPF = new DecompositionLPF(grade);
        dHPF = new DecompositionHPF(grade);
        rLPF = new ReconstructionLPF(grade);
        rHPF = new ReconstructionHPF(grade);
    }

    /**
     *
     * @param data
     * @param cA
     * @param cD
     *
     * @since 2013-08-19
     */
    public void DWT(List<Short> data, List<Short> cA, List<Short> cD) {
        short sample, skipFilteredSample;
        boolean state = true;
        cA.clear();
        cD.clear();
        dLPF.clear();
        dHPF.clear();
        for (int i = 0; i < data.size(); i++) {
            sample = data.get(i);
            if (state == true) {
                cA.add((short) dLPF.filter(sample));
                cD.add((short) dHPF.filter(sample));
                state = false;
            } else {
                skipFilteredSample = (short) dLPF.filter(sample);
                skipFilteredSample = (short) dHPF.filter(sample);
                state = true;
            }
        }
    }

    /**
     *
     * @param cA
     * @param cD
     * @param data
     *
     * @since 2013-09-28
     */
    public void iDWT(List<Short> cA, List<Short> cD, List<Short> data) {
        data.clear();
        for (int i = 0; i < cA.size(); i++) {
            data.add((short) (rLPF.filterSample(cA.get(i)) + rHPF.filterSample(cD.get(i))));
            data.add((short) (rLPF.filterSample((short) 0) + rHPF.filterSample((short) 0)));
        }
    }
}
